package logic

import (
	"context"
	"zhihu/zhihu_rpc/zhihurpcclient"

	"zhihu/api/internal/svc"
	"zhihu/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type FindPasswordLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewFindPasswordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FindPasswordLogic {
	return &FindPasswordLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *FindPasswordLogic) FindPassword(req *types.FindPasswordRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	password, err := l.svcCtx.ZhiHuRpc.FindPassword(l.ctx, &zhihurpcclient.FindPasswordRequest{
		Phone:    req.Phone,
		Code:     req.Code,
		Account:  req.Account,
		Password: req.Password,
	})
	if err != nil {
		return &types.Response{
			Code:    500,
			Message: err.Error(),
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Code:    200,
		Message: "密码修改成功",
		Data:    password,
	}, nil
}
